const {getErr} = require("./getSendResult");
const jwt = require("./jwt")
module.exports = (req, res, next) => {
    // let token = req.cookies.token;
    // if(!token){
    //     token = req.headers.authorization;
    // }
    // if(!token){
    //     //未认证
    //     handleNonAuth(req,res, next);
    //     return;
    // }
    // //认证通过
    // next();
    const result = jwt.verifyToken(req)
    if(result){
        req.userId = result.id
        next()
    }else{
        handleNonAuth(req,res, next);
    }
    
}

function handleNonAuth(req,res, next){
    res.status(401).send(getErr("当前用户未认证",403));
}